﻿using Enterprises.Wpf.Core.Helper;

namespace Enterprises.Wpf.Core.Mqtt
{
    /// <summary>
    /// Mqtt发送的消息封装对象，是对 <see cref="T:HslCommunication.MQTT.MqttApplicationMessage" /> 对象的封装，添加了序号，还有是否重发的信息<br />
    /// The message encapsulation object sent by Mqtt is an encapsulation of the <see cref="T:HslCommunication.MQTT.MqttApplicationMessage" /> object, with the serial number added, and whether to retransmit
    /// </summary>
    public class MqttPublishMessage
    {
        /// <summary>
        /// 是否第一次发送数据信息<br />
        /// Whether to send data information for the first time
        /// </summary>
        public bool IsSendFirstTime { get; set; }

        /// <summary>
        /// 当前的消息的标识符，当质量等级为0的时候，不需要重发以及考虑标识情况<br />
        /// The identifier of the current message, when the quality level is 0, do not need to retransmit and consider the identification situation
        /// </summary>
        public int Identifier { get; set; }

        /// <summary>
        /// 当前发布消息携带的mqtt的应用消息，包含主题，消息等级，负载。<br />
        /// The application message of mqtt carried in the current published message, including the subject, message level, and load.
        /// </summary>
        public MqttApplicationMessage Message { get; set; }

        /// <summary>
        /// 实例化一个默认的对象<br />
        /// Instantiate a default object
        /// </summary>
        public MqttPublishMessage()
        {
            IsSendFirstTime = true;
        }
    }

    /// <summary>
    /// 订阅的消息类，用于客户端向服务器请求订阅的信息<br />
    /// Subscribed message class, used by the client to request subscription information from the server
    /// </summary>
    public class MqttSubscribeMessage
    {
        /// <summary>
        /// 这个字段表示应用消息分发的服务质量等级保证。分为，最多一次，最少一次，正好一次<br />
        /// This field indicates the quality of service guarantee for application message distribution. Divided into, at most once, at least once, exactly once
        /// </summary>
        /// <remarks>
        /// 在实际的开发中的情况下，最多一次是最省性能的，正好一次是最消耗性能的，如果应有场景为推送实时的数据，那么，最多一次的性能是最高的
        /// </remarks>
        public MqttQualityOfServiceLevel QualityOfServiceLevel { get; set; }

        /// <summary>
        /// 当前的消息的标识符，当质量等级为0的时候，不需要重发以及考虑标识情况<br />
        /// The identifier of the current message, when the quality level is 0, do not need to retransmit and consider the identification situation
        /// </summary>
        public int Identifier { get; set; }

        /// <summary>
        /// 当前订阅的所有的主题的数组信息<br />
        /// Array information of all topics currently subscribed
        /// </summary>
        public string[] Topics { get; set; }

        /// <summary>
        /// 实例化一个默认的对象<br />
        /// Instantiate a default object
        /// </summary>
        public MqttSubscribeMessage()
        {
            QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce;
            Identifier = 1;
        }

        /// <inheritdoc />
        public override string ToString()
        {
            return "MqttSubcribeMessage" + SoftBasic.ArrayFormat(Topics);
        }
    }

}
